<?php

class Db_Tables2_BBuAuth
{
	function __construct() {
		$this->dealers_db = Zend_Registry::get("dealers_db");
	}
	
	function GetStaffsInfo($emp_id, $ct=NULL)
	{
		$result = array();
        
        $mod_params = new Db_Tables2_BDictParams();
        $sys_id = $mod_params->GetSysId();
		
		if(1)
		{
			if(intval($emp_id))
			{
				$select = $this->dealers_db->select();
				$select->from("dealers_db".$sys_id.".b_bu_auth as a", array("title"));
				$select->joinLeft("hxb_db".$sys_id.".auth_emp as e", "e.id=a.emp_id", array("id", "realName"));
				$select->where("e.parentEmpId = ?", intval($emp_id));
				$data = $this->dealers_db->fetchAll($select);
				
				if(!empty($data))
				{
					$mod_user = new Db_Tables2_User();
					
					foreach($data as $d)
					{
						$result[$d['id']] = array(
							"title" => $d['title'],
							"emp_name" => $d['realName']
						);
						
						if($ct) //计算下级人数
						{
							$staff_ct = $mod_user->StaffCount($d['id']);
							$result[$d['id']]['staff_ct'] = $staff_ct;
						}
					}
				}
			}
		}
		
		return $result;
	}
}